/**
* @file gui_key_frontend.h
* @brief key frontend
* @details 
* @author huangbin
* @version V1.0.0
* @date 2025-06-12
* @copyright All documents are copyrighted by Shenzhen Xinlongwei Technology Co., LTD.
*            They may not be used for commercial purposes without permission
*/


#ifndef __GUI_KEY_FRONTEND_H__
#define __GUI_KEY_FRONTEND_H__

/*============================ INCLUDES ======================================*/
#include "../gui_cfg.h"

#include "../gui_message.h"

#ifdef   __cplusplus
extern "C" {
#endif

#if defined(__clang__)
#   pragma clang diagnostic push
#   pragma clang diagnostic ignored "-Wmissing-declarations"
#   pragma clang diagnostic ignored "-Wmicrosoft-anon-tag"
#   pragma clang diagnostic ignored "-Wpadded"
#endif

/*============================ MACROS ========================================*/

/* OOC header, please DO NOT modify  */
#ifdef __GUI_KEY_FRONTEND_IMPLEMENT__
#   undef   __GUI_KEY_FRONTEND_IMPLEMENT__
#   define  __ARM_2D_IMPL__
#elif defined(__GUI_KEY_FRONTEND_INHERIT__)
#   undef   __GUI_KEY_FRONTEND_INHERIT__
#   define __ARM_2D_INHERIT__
#endif
#include "arm_2d_utils.h"

/*============================ MACROS ========================================*/
/*============================ MACROFIED FUNCTIONS ===========================*/
/*============================ TYPES =========================================*/

typedef struct gui_msg_key_frontend_cfg_t {

    uint32_t u8LongPressThresholdIn100Ms    : 8;
    uint32_t u4First3RepeatInterval         : 4;
    uint32_t u4RestRepeatInterval           : 4;

    uint32_t u10DoubleClickLimit            : 10;
    uint32_t                                : 1;
    uint32_t bDisableDoublePressedDetection : 1;
    uint32_t bDisableLongPressDetection     : 1;
    uint32_t bRemoveUnexpectedKeyMessage    : 1;
    
} gui_msg_key_frontend_cfg_t;


typedef struct gui_msg_key_frontend_t {
    implement(gui_msg_frontend_t);       /* base */

ARM_PRIVATE(

    gui_helper_msg_fifo_t tInternalFIFO[2];
    int64_t lTimestamp[3];

    gui_msg_key_frontend_cfg_t tCFG;

    struct {
        uint8_t chState;
        uint16_t hwLastKeyValue;
        void *ptTargetWidget;
    } Stage0;

    struct {
        uint8_t chState;
        uint16_t hwLastKeyValue;
        void *ptTargetWidget;
    } Stage1;

    struct {
        uint8_t chPT;
        gui_helper_msg_fifo_t tTempFIFO;
    } Stage2;

)

} gui_msg_key_frontend_t;

/*============================ GLOBAL VARIABLES ==============================*/
/*============================ PROTOTYPES ====================================*/

ARM_PUBLIC_METHOD(

    extern
    ARM_NONNULL(1)
    void gui_helper_msg_key_frontend_init(gui_msg_key_frontend_t *ptThis,
                                          gui_msg_key_frontend_cfg_t *ptCFG);

    extern
    ARM_NONNULL(1, 2)
    gui_msg_key_frontend_cfg_t *gui_helper_msg_key_frontend_settings_get(
                                            gui_msg_key_frontend_t *ptThis,
                                            gui_msg_key_frontend_cfg_t *ptCFG);
    
    extern
    ARM_NONNULL(1, 2)
    void gui_helper_msg_key_frontend_settings_set(
                                            gui_msg_key_frontend_t *ptThis,
                                            gui_msg_key_frontend_cfg_t *ptCFG);

    extern
    ARM_NONNULL(1)
    bool gui_helper_msg_key_frontend_long_pressing_detection(
                                            gui_msg_key_frontend_t *ptThis,
                                            bool bEnable);

    extern
    ARM_NONNULL(1)
    bool gui_helper_msg_key_frontend_double_pressed_detection(
                                            gui_msg_key_frontend_t *ptThis,
                                            bool bEnable);

)

#if defined(__clang__)
#   pragma clang diagnostic pop
#endif

#ifdef   __cplusplus
}
#endif

#endif
